﻿
/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

function setTimePicker(Stime,Etime,M) {

   // alert();
    var op1;
    var op2;
  
    var length;
   
//    if (modeop == "A") {
       // Stime = document.getElementById("ctl00_ContentPlaceHolder1_txtStartTime_picked").value;
    //Etime = document.getElementById("ctl00_ContentPlaceHolder1_txtEndTime_picked").value;

    // Stime = document.getElementById("ctl00_ContentPlaceHolder1_txtStartTime_picked").value;
    /// Etime = document.getElementById("ctl00_ContentPlaceHolder1_txtEndTime_picked").value;

       // alert(Stime);
       // alert(Etime);
   // }
//    if (modeop == "E") {
//        Stime = document.getElementById("ctl00_ContentPlaceHolder1_txtStartTimeEdit").value;
//        Etime = document.getElementById("ctl00_ContentPlaceHolder1_txtEndTimeEdit").value;
//    }
    var hr1 = Stime.split(":");
    var min1 = hr1[1].split(" ");
  
    var hr2 = Etime.split(":");
    var min2 = hr2[1].split(" ");

    if (min1[1] == "am" && min2[1] == "am") {
        if (parseInt(hr1[0]) == 12) {
            op1 = parseInt(hr1[0]) * 60 + parseInt(min1[0]);
        }
        else {
            op1 = (parseInt(hr1[0]) + 12) * 60 + parseInt(min1[0]);
        }

        if (parseInt(hr2[0]) == 12) {
            op2 = parseInt(hr2[0]) * 60 + parseInt(min2[0]);
        }
        else {
            op2 = (parseInt(hr2[0]) + 12) * 60 + parseInt(min2[0]);
            
        }
        length = parseInt(op2) - parseInt(op1);
    }

    if (min1[1] == "am" && min2[1] == "pm") {
        if (parseInt(hr1[0]) == 12) {
            op1 = parseInt(hr1[0]) * 60 + parseInt(min1[0]);
        }
        else {
            op1 = (parseInt(hr1[0])) * 60 + parseInt(min1[0]);
        }

        if (parseInt(hr2[0]) == 12) {
            op2 = (parseInt(hr2[0]) + 12) * 60 + parseInt(min2[0]);
        }
        else {
            op2 = ((parseInt(hr2[0]) + 12) * 60 + parseInt(min2[0]));
        }

        if (parseInt(hr1[0]) == 12 && parseInt(hr2[0]) == 12 && parseInt(min1[0]) == 00 && parseInt(min2[0]) == 00) {
            length = (parseInt(op2) - parseInt(op1));
        }
        else if(parseInt(hr1[0]) == 12 && parseInt(hr2[0]) < 12)
        {
            length = (parseInt(op2) - parseInt(op1)) + (12*60) ;
        }
        else if (parseInt(hr1[0]) < 12 && parseInt(hr2[0]) == 12) {
            length = (parseInt(op2) - parseInt(op1)) - (12 * 60);
        }
        else 
        {
          length = (parseInt(op2) - parseInt(op1));
        }
       
    }

    if (min1[1] == "pm" && min2[1] == "pm") {
        if (parseInt(hr1[0]) == 12) {
            op1 = parseInt(hr1[0]) * 60 + parseInt(min1[0]);
        }
        else {
            op1 = parseInt(hr1[0]) * 60 + parseInt(min1[0]);
            
        }

        if (parseInt(hr2[0]) == 12) {
            op2 = (parseInt(hr2[0])) * 60 + parseInt(min2[0]);
        }
        else {
            op2 = (parseInt(hr2[0])) * 60 + parseInt(min2[0]);
           
        }
        length = parseInt(op2) - parseInt(op1);
    }

    if (min1[1] == "pm" && min2[1] == "am") {
        if (parseInt(hr1[0]) == 12) {
            op1 = parseInt(hr1[0]) * 60 + parseInt(min1[0]);
        }
        else {
            op1 = (parseInt(hr1[0])) * 60 + parseInt(min1[0]);
        }

        if (parseInt(hr2[0]) == 12) {
            op2 = (parseInt(hr2[0]) + 12) * 60 + parseInt(min2[0]);
        }
        else {
            op2 = ((parseInt(hr2[0]) + 12) * 60 + parseInt(min2[0]));
        }
        
        if (parseInt(hr1[0]) == 12 && parseInt(hr2[0]) == 12 && parseInt(min1[0]) == 00 && parseInt(min2[0]) == 00) {
            length = (parseInt(op2) - parseInt(op1));
        }
        else if (parseInt(hr1[0]) == 12 && parseInt(hr2[0]) < 12) {
            length = (parseInt(op2) - parseInt(op1)) + (12 * 60);
        }
        else if (parseInt(hr1[0]) < 12 && parseInt(hr2[0]) == 12) {
            length = (parseInt(op2) - parseInt(op1)) - (12 * 60);
        }
        else {
            length = (parseInt(op2) - parseInt(op1));
        }
    }
    if (M == "A") {
        document.getElementById("ctl00_ContentPlaceHolder1_txtLength").value = length;
    }
    if (M == "E") {
        document.getElementById("ctl00_ContentPlaceHolder1_txtLengthEdit").value = length;
    }
}




